package com.zkt.oss.service;

import com.zkt.oss.adapter.StorageAdapter;
import com.zkt.oss.constants.FileConstant;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 赵开泰
 * @program jc-club
 * @date 2025/3/17 22:21
 * @description 文件服务层，适配不同的存储服务层
 **/

@Service
public class FileService {
	
	private final StorageAdapter storageAdapter;
	
	public FileService(StorageAdapter storageAdapter) {
		this.storageAdapter = storageAdapter;
	}
	
	/**
	 * 列出所有桶
	 *
	 * @return 所有桶名称
	 */
	public List<String> getAllBuckets() {
		return storageAdapter.getAllBuckets();
	}
	
	/**
	 * 上传头像
	 *
	 * @param file 头像图片文件
	 * @return 文件路径
	 */
	public String uploadAvatar(MultipartFile file) {
		String userAvatarPath = FileConstant.getUserAvatarPath();
		storageAdapter.uploadFile(file, FileConstant.BUCKET_NAME, userAvatarPath);
		return storageAdapter.getUrl(FileConstant.BUCKET_NAME, userAvatarPath);
	}
	
}
